﻿using Gym.Application.Common.Interfaces;
using Gym.Domain.Common.Interfaces;
using Gym.Infrastructure.Persistence;
using Gym.Infrastructure.Persistence.Repositories;
using Gym.Infrastructure.Services;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Runtime.InteropServices.JavaScript.JSType;

namespace Gym.Infrastructure
{
    public static class DependencyInjection
    {
        public static IServiceCollection AddInfrastructure(this IServiceCollection services)
        {
            services
            .AddServices()
            .AddPersistence();

            return services;
        }

        public static IServiceCollection AddServices(this IServiceCollection services)
        {
            services.AddScoped<IDateTimeProvider, SystemDateTimeProvider>();
            return services;
        }

        public static IServiceCollection AddPersistence(this IServiceCollection services)
        {
            services.AddDbContext<GymDbContext>(options =>
                options.UseSqlite("Data Source = DomeGym.db"));

            services.AddScoped<IAdminsRepository, AdminsRepository>();
            services.AddScoped<IGymsRepository, GymsRepository>();
            services.AddScoped<IParticipantsRepository, ParticipantsRepository>();
            services.AddScoped<IRoomsRepository, RoomsRepository>();
            services.AddScoped<ISessionsRepository, SessionsRepository>();
            services.AddScoped<ISubscriptionsRepository, SubscriptionsRepository>();
            services.AddScoped<ITrainersRepository, TrainersRepository>();

            return services;
        }
    }
}
